package xff;

import java.util.List;
import burp.IHttpRequestResponse;
import burp.IParameter;
import burp.IRequestInfo;
import burp.IResponseInfo;
import burp.IExtensionHelpers;

public class MyMessage {

	private String protocol;
	private String host;
	private int port;
	private String url;

	private String request;
	private String Method;
	private List<IParameter> parameters;
	private List<String> requestHeader;
	private String requestBody;

	private int responseStatusCode;
	private String response;
	private List<String> responseHeader;
	private String responseBody;
	private String selectString;

	public MyMessage() {
		
	}
	
	public MyMessage(MyMessage myMessage) {
		this.host = myMessage.getHost();
		this.Method = myMessage.getMethod();
		this.parameters = myMessage.getParameters();
		this.port = myMessage.getPort();
		this.protocol = myMessage.getProtocol();
		this.url = myMessage.getUrl();
		this.request = myMessage.getRequest();
		this.requestBody = myMessage.getRequestBody();
		this.requestHeader = myMessage.getRequestHeader();
		this.response = myMessage.getResponse();
		this.responseBody = myMessage.getResponseBody();
		this.responseHeader = myMessage.getResponseHeader();
		this.responseStatusCode = myMessage.getResponseStatusCode();

	}

	public MyMessage(IHttpRequestResponse message, IExtensionHelpers helpers) {

		this.request = helpers.bytesToString(message.getRequest());
		this.protocol = message.getHttpService().getProtocol();

		this.host = message.getHttpService().getHost();
		this.port = message.getHttpService().getPort();
		this.url = helpers.analyzeRequest(message).getUrl().toString();

		IRequestInfo requestInfo = helpers.analyzeRequest(message);

		this.requestHeader = requestInfo.getHeaders();
		this.requestBody = (this.request.substring(requestInfo.getBodyOffset(), this.request.length()));
		this.Method = requestInfo.getMethod();

		parameters = helpers.analyzeRequest(message).getParameters();

		IResponseInfo ResponseInfo = helpers.analyzeResponse(message.getResponse());

		this.response = helpers.bytesToString(message.getResponse());
		this.responseHeader = ResponseInfo.getHeaders();
		this.responseStatusCode = ResponseInfo.getStatusCode();
		this.responseBody = (this.response.substring(ResponseInfo.getBodyOffset(), this.response.length()));

	}

	public MyMessage(IHttpRequestResponse message, IExtensionHelpers helpers, int bounds[]) {

		this.request = helpers.bytesToString(message.getRequest());
		this.protocol = message.getHttpService().getProtocol();

		this.host = message.getHttpService().getHost();
		this.port = message.getHttpService().getPort();
		this.url = helpers.analyzeRequest(message).getUrl().toString();

		IRequestInfo requestInfo = helpers.analyzeRequest(message);

		this.requestHeader = requestInfo.getHeaders();
		this.requestBody = (this.request.substring(requestInfo.getBodyOffset(), this.request.length()));
		this.Method = requestInfo.getMethod();

		parameters = helpers.analyzeRequest(message).getParameters();

		IResponseInfo ResponseInfo = helpers.analyzeResponse(message.getResponse());

		this.response = helpers.bytesToString(message.getResponse());
		this.responseHeader = ResponseInfo.getHeaders();
		this.responseStatusCode = ResponseInfo.getStatusCode();
		this.responseBody = (this.response.substring(ResponseInfo.getBodyOffset(), this.response.length()));

		if (bounds != null && 2 == bounds.length) {
			this.selectString = this.response.substring(bounds[0], bounds[1]);
		} else {
			this.selectString = "";
		}

	}

	public String getResponse() {
		return response;
	}

	public void setResponse(String response) {
		this.response = response;
	}

	public String getProtocol() {
		return protocol;
	}

	public void setProtocol(String protocol) {
		this.protocol = protocol;
	}

	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getRequest() {
		return request;
	}

	public void setRequest(String request) {
		this.request = request;
	}

	public String getMethod() {
		return Method;
	}

	public void setMethod(String method) {
		Method = method;
	}

	public List<String> getRequestHeader() {
		return requestHeader;
	}

	public void setRequestHeader(List<String> requestHeader) {
		this.requestHeader = requestHeader;
	}

	public String getRequestBody() {
		return requestBody;
	}

	public void setRequestBody(String requestBody) {
		this.requestBody = requestBody;
	}

	public int getResponseStatusCode() {
		return responseStatusCode;
	}

	public void setResponseStatusCode(int responseStatusCode) {
		this.responseStatusCode = responseStatusCode;
	}

	public List<String> getResponseHeader() {
		return responseHeader;
	}

	public void setResponseHeader(List<String> responseHeader) {
		this.responseHeader = responseHeader;
	}

	public String getResponseBody() {
		return responseBody;
	}

	public void setResponseBody(String responseBody) {
		this.responseBody = responseBody;
	}

	public boolean compare(MyMessage myMessage) {
		if (0 == this.url.compareTo(myMessage.getUrl())) {
			return true;
		}

		return false;
	}

	public boolean compareContainSelectString(MyMessage myMessage) {
		if (0 == this.url.compareTo(myMessage.getUrl())
				&& 0 == this.selectString.compareTo(myMessage.getSelectString())) {
			return true;
		}
		return false;
	}

	public List<IParameter> getParameters() {
		return parameters;
	}

	public void setParameters(List<IParameter> parameters) {
		this.parameters = parameters;
	}

	public String getSelectString() {
		return selectString;
	}

	public void setSelectString(String selectString) {
		this.selectString = selectString;
	}

}
